<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">

          <a-col :md="6" :sm="8">
            <a-form-item label="订单号">
              <a-input placeholder="请输入订单号" v-model="queryParam.orderNumber"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="合作编号">
              <a-input placeholder="请输入合作编号" v-model="queryParam.takeOrders"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="订单类型">
              <a-select placeholder="请输入订单类型" v-model="queryParam.orderType">
                <a-select-option v-for="item in orderTypes" :key="item.key" :value="item.key">{{ item.val }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="抢单分类">
              <a-select placeholder="抢单分类" v-model="queryParam.grabType">
                <a-select-option v-for="item in grabTypes" :key="item.key" :value="item.key">{{ item.val }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
            <span style="float: right;overflow: hidden;margin-bottom: 10px" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
    </div>
    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a v-if="record.settlementStatus==2" @click="handleclose(record)">确认结算</a>
          <a-divider v-if="record.settlementStatus==2" type="vertical" />
          <a v-if="record.settlementStatus==2" @click="uplodclose(record)">上传结算图</a>
          <a-divider v-if="record.settlementStatus==2" type="vertical" />
           <a href="javascript:;" @click="handleDetail(record)">详情</a>
              <a-divider v-if="record.orderStatus==0" type="vertical" />
           <a-popconfirm v-if="record.orderStatus==0" title="确定删除吗?" @confirm="() => handleDelete(record.id)">
           <a>删除</a>
           </a-popconfirm>
        </span>
        <span slot="cost" slot-scope="text">
          {{text}}元
        </span>
        <span slot="closingCost" slot-scope="text, record">
          <div style="width: 180px" class="contText" >加价:{{record.raiseNumber?record.raiseNumber+'元':'暂无'}}，结算{{Number(record.raiseNumber)+Number(record.cost)}}元</div>
        </span>
        <span slot="fieldText" slot-scope="text">
          <div style="width: 220px"  class="contText" :title="text">{{ text }}</div>
        </span>
        <span slot="orderStatus" slot-scope="text,record">
<!--           <a-alert  :type="getColor(record)"  :message="text"    />-->
         <a-tag  :color="getColor(record)" style="width: 100%;color: rgba(0, 0, 0, 0.65);height: 38px;font-size: 14px;line-height: 2.5;" >{{text}}</a-tag>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <orderForm-modal ref="modalForm" @ok="modalFormOk"></orderForm-modal>
    <CloseOrderFormModal ref="closeOrderFormModal" @ok="modalFormOk"></CloseOrderFormModal>

    <UploadImgByOrder ref="uploadImgByOrder" @ok="modalFormOk" ></UploadImgByOrder>
  </a-card>
</template>

<script>
import CloseOrderFormModal from './modules/CloseOrderFormModal'
import OrderFormModal from './modules/OrderFormModal'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import {Dict}   from '@/api/Dict'
import {getAction} from "@api/manage";
import UploadImgByOrder from "@comp/tools/UploadImgByOrder";

export default {
  name: "OrderFormList",
  mixins:[JeecgListMixin,Dict],
  components: {
    OrderFormModal,
    CloseOrderFormModal,
    UploadImgByOrder
  },
  data () {
    return {
      description: '订单管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key:'rowIndex',
          width:30,
          align:"center",
          customRender:function (t,r,index) {
            return parseInt(index)+1;
          }
        },
        {
          title: '创建时间',
          align:"center",
          dataIndex: 'createTime',
          width: 160
        },
        /*{
          title: '编号',
          align:"center",
          dataIndex: 'id',
          width: 30
        },*/
        {
          title: '合作编号',
          align:"center",
          dataIndex: 'takeOrders',
        },
        {
          title: '指派人',
          align:"center",
          dataIndex: 'createByName',
        },
        {
          title: '订单号',
          align:"center",
          dataIndex: 'orderNumber',
        },
        {
          title: '订单类型',
          align:"center",
          dataIndex: 'orderType_dictText',
        },
        {
          title: '抢单分类',
          align:"center",
          dataIndex: 'grabType_dictText',
        },
        {
          title: '要求完成时间',
          align:"center",
          dataIndex: 'finishTime',
          width: 160
        },
        {
          title: '结算费用',
          align:"center",
          dataIndex: 'raiseNumber',
          scopedSlots: { customRender: 'closingCost' },
          width: 180,
          ellipsis: true,
        },

        {
          title: '订单状态',
          align:"center",
          dataIndex: 'orderStatus_dictText',
          scopedSlots: { customRender: 'orderStatus' },
          width: 150
        },
        /*{
          title: '结算状态',
          align:"center",
          dataIndex: 'settlementStatus_dictText',
          width: 90
        },*/
        {
          title: '操作',
          dataIndex: 'action',
          align:"center",
          scopedSlots: { customRender: 'action' },
        }
      ],
      url: {
        list: "/orderForm/orderForm/list",
        edit: "/orderForm/orderForm/edit",
        delete: "/orderForm/orderForm/delete",
        deleteBatch: "/orderForm/orderForm/deleteBatch",
        exportXlsUrl: "orderForm/orderForm/exportXls",
        importExcelUrl: "orderForm/orderForm/importExcel",
      },
    }
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  methods: {
    uplodclose(record){
      this.$refs.uploadImgByOrder.edit(record);
      this.$refs.uploadImgByOrder.visible=true;
    },
    handleclose(record){
      console.log("orderStatus-->",record.orderStatus);
      this.$refs.closeOrderFormModal.edit(record);
      this.$refs.closeOrderFormModal.title="结算";
      /*if(record.orderStatus==3){
        this.showClosemessage=true;
        let Numbers= Number(record.raiseNumber)+Number(record.cost);
        content='正常结算:加价'+record.raiseNumber+"元,结算"+Numbers+"元";
      }
      if(record.orderStatus==6){
        this.showClosemessage=true;
        let Numbers= Number(record.raiseNumber)+Number(record.cost)-50;
        content='逾期结算:加价'+record.raiseNumber+"元,预期-"+50+"元,结算"+Numbers+"元";
      }*/

    },
    loadData(arg) {
      if(!this.url.list){
        this.$message.error("请设置url.list属性!")
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1;
      }
      var params = this.getQueryParams();//查询条件
      params.settlementStatus=2;
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records;
          this.ipagination.total = res.result.total;
        }
      })
    },

  }
}
</script>
<style lang="less" scoped>
/** Button按钮间距 */
.ant-btn {
  margin-left: 3px
}
.ant-card-body .table-operator{
  margin-bottom: 18px;
}
.ant-table-tbody .ant-table-row td{
  padding-top:15px;
  padding-bottom:15px;
}
.anty-row-operator button{margin: 0 5px}
.ant-btn-danger{background-color: #ffffff}

.ant-modal-cust-warp{height: 100%}
.ant-modal-cust-warp .ant-modal-body{height:calc(100% - 110px) !important;overflow-y: auto}
.ant-modal-cust-warp .ant-modal-content{height:90% !important;overflow-y: hidden}
.contText{
  overflow: hidden;/*内容超出后隐藏*/
  text-overflow: ellipsis;/* 超出内容显示为省略号*/
  white-space: nowrap;/*文本不进行换行*/
}
</style>